

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using JTC.MiniCommerce.Core;
using JTC.MiniCommerce.Localization;
using JTC.MiniCommerce.Store.Web.Controls;
using JTC.MiniCommerce.Store;

namespace JTC.MiniCommerce.Web.controls.navigation {
  public partial class favoritecategories : SiteControl {

    #region Page Events

    /// <summary>
    /// Handles the Load event of the Page control.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
    protected void Page_Load(object sender, EventArgs e) {
      try {
        LoadFavoriteCategories();
      }
      catch (Exception ex) {
        Logger.Error(typeof(favoritecategories).Name + "Page_Load", ex);
      }
    }

    #endregion

    #region Methods

    #region Protected

    /// <summary>
    /// Gets the catalog URL.
    /// </summary>
    /// <param name="categoryId">The category id.</param>
    /// <returns></returns>
    protected string GetCatalogUrl(string categoryId) {
      return string.Format("~/catalog.aspx?cid={0}", categoryId);
    }

    #endregion

    #region Private

    /// <summary>
    /// Loads the favorite categories.
    /// </summary>
    private void LoadFavoriteCategories() {
      if (base.MasterPage.SiteSettings.CollectBrowsingCategory) {
        DataSet ds = new CategoryController().FetchFavoriteCategories(WebUtility.GetUserName());
        if (ds.Tables[0].Rows.Count > 0) {
          LocalizationUtility.AddPanelText(pnlFavoriteCategories);
          rptrFavoriteCategories.DataSource = ds;
          rptrFavoriteCategories.DataBind();
        }
      }
    }

    #endregion

    #endregion

  }
}